package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    TbClueServiceImpl tbClueService;

    /**
     * @param tbClueTrackRecord
     * @return int
     * @author chenqingxu
     * @description 添加线索跟进记录
     */
    @Override
    @Transactional
    public int addClueTrackRecord(TbClueTrackRecord tbClueTrackRecord) {
//        获取clueId
        Long clueId = tbClueTrackRecord.getClueId();
//        1.添加线索跟进数据
//        1.1 设置线索为类型为“0”
        tbClueTrackRecord.setType("0");
//        1.2 添加数据进入数据库
        int i = tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);

//        2.更改线索表中被跟进线索的status
        tbClueService.updateStauts(clueId, "2", tbClueTrackRecord.getNextTime());
        return i;
    }

    /**
     * @param clueId
     * @return java.util.List<com.huike.clues.domain.TbClueTrackRecord>
     * @author chenqingxu
     * @description 显示选中线索的跟进记录
     */
    @Override
    public List<TbClueTrackRecord> selectByClueId(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordMapper.selectByClueId(clueId);
        return tbClueTrackRecords;
    }
}
